<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <title>填写日报</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <base href="http://localhost:8888"/>
  <link rel="stylesheet" href="css/font.css">
  <link rel="stylesheet" href="css/weadmin.css">
</head>

<body>
<div class="weadmin-body">
  <fieldset class="layui-elem-field layui-field-title">
    <legend>日报系统</legend>
  </fieldset>
  <form class="layui-form">
    <div class="layui-form-item">
      <label for="title" class="layui-form-label">
        日报主题
      </label>
      <div class="layui-input-inline">
        <input type="text" id="title" name="dailyTitle" required="" lay-verify="required" autocomplete="off"
               class="layui-input">
      </div>
    </div>

    <div class="layui-form-item layui-form-text" style="width: 50%">
      <label class="layui-form-label">日报内容</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" class="layui-textarea" name="content"></textarea>
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label">抄送人</label>
      <div class="layui-input-block">
        <!-- 利用thymeleaf的each标签，遍历list，以领导id为实际传值，以领导名称为显示内容 -->
        <input type="checkbox" name="leaderId" th:each="leader:${leaderList}" th:value="${leader.leaderId}" th:title="${leader.leaderName}">
      </div>
    </div>

    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <button class="layui-btn" lay-filter="add" lay-submit="">提交日报</button>
    </div>
  </form>
</div>
<script src="lib/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript">
  layui.config({
    base: 'js/'
  }).extend({ //设定模块别名
    admin: 'admin'
    , menu: 'menu'
    , http: 'http'
  });
  layui.use(['form', 'layer','jquery'], function () {
    var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery
    form.render();

    //监听提交
    form.on('submit(add)', function (data) {
      console.log(data.field);
      var arr_box = [];
      $('input[type=checkbox]:checked').each(function() {
        arr_box.push($(this).val());
      });
      console.log(arr_box);
      data.field.leaderId = arr_box;
      //提交数据
      $.ajax({
        url: 'http://localhost:8888/member/work/newspaper/submit',
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify(data.field),
        success: function (res) {
          console.log('success');
          if (res.result === "SUCCESS") {
            layer.alert("提交成功", { icon: 6 });
          } else {
            layer.msg(res.message);
          }
        }
      });
      return false;
    });
  });
</script>
</body>

</html>